<?php

namespace app\api\model;

class RankingRecords extends Common
{
    static public function index($types, $user_id, $to_user='', $count, $cluster_id='')
    {
        if ($count + 0) {

            $types = explode(',', $types);

            foreach ($types as $item) {

                $sum = $count;

                switch ($item) {
                    case 1:
                        $tmp_1 = min($user_id, $to_user);
                        $tmp_2 = max($user_id, $to_user);

                        $sum = $count * 0.1;
                        break;
                    case 2:
                    case 4:
                    case 6:
                        $tmp_1 = $to_user;
                        $tmp_2 = $user_id;
                        break;
                    case 3:
                    case 5:
                        $tmp_1 = $user_id;
                        $tmp_2 = $to_user;
                        break;
                }

                self::create([
                    'types' => $item,
                    'user_id' => $tmp_1,
                    'to_user' => $tmp_2,
                    'cluster_id' => $cluster_id,
                    'count' => $sum,
                    'create_time' => time()
                ]);
            }
        }
    }
}
